import React from 'react'
import { Router, Route, IndexRoute, useRouterHistory } from 'dva/router'
import PropTypes from 'prop-types'
import { createHashHistory } from 'history'
const loginRequireAuth = function(nextState, replace) {
  if (!localStorage['token']) {
    replace({
      pathname: '/',
      state: { nextPathname: nextState.location.pathname }
    })
  }
}
// var appHistory = useRouterHistory(createHashHistory)({queryKey:false})
// const ordersAuth = (nextState,replace))=>{
//     if(!window.localStorage['setting']){
//         replace({

//         })
//     }
// }
// function route
// const routes = {
//     path:'/',
//     // component
//     indexRoute:{component:require('./routes/IndexPage/index.jsx')},
//     childRoutes:[
//         {path:'store_list',component:require('./routes/Stores/list/Stores.js')}
//     ]
// }
// export default routes
export default function({ history }) {
  // console.log(history)
  // var appHistory = useRouterHistory(history.createLocation)({queryKey:false})
  return <Router history={history}>
      <Route path="/">
        <IndexRoute component={require('./routes/IndexPage/index.jsx')} />
        <Route path="log" component={require('./routes/Login.js')} />

        <Route path="reg" component={require('./routes/Register.js')} />
        <Route path="invit" component={require('./routes/Invit.js')} />
        {/* <Route component={require('./routes/IndexPage.js')}>
          <Route path="log" component={require('./routes/Login.js')} />

          <Route path="reg" component={require('./routes/Register.js')} />
          <Route path="invit" component={require('./routes/Invit.js')} />
        </Route> */}
        <Route path="regist" component={require('./routes/Login/Regist')} />
        <Route path="home" component={require('./routes/IndexPage/index.jsx')} />
        <Route path="app" component={require('./routes/App.js')} onEnter={loginRequireAuth}>
          <Route path="set" component={require('./routes/Setting.js')} />
          <Route path="setpany" component={require('./routes/Set/Company.js')} />
          <Route path="home" component={require('./routes/Home.js')} />
          <Route path="customers" component={require('./routes/Customer/Customer.js')} />

          <Route path="clues" component={require('./routes/Clue/Clue.js')} />
          <Route path="commodity" component={require('./routes/Commodity/Commodity.js')} />

          <Route path="stores" component={require('./routes/Stores/Index.js')} />
          <Route path="newcha" component={require('./routes/Stores/Add/Regions.js')} />
          <Route path="store_list" component={require('./routes/Stores/list/Stores.js')} />
          <Route path="store_new" component={require('./routes/Stores/Add/Stores.js')} />

          <Route path="orders" component={require('./routes/Orders/Orders.js')} />

          <Route path="strategies" component={require('./routes/Strategies/Index.js')} />
          <Route path="newacunt" component={require('./routes/Users/CreateAccount.js')} />
          <Route path="users" component={require('./routes/Users/AccountList')} />
          <Route path="account" component={require('./routes/Companies/Index.js')} />
          <Route path="company" component={require('./routes/Companies/Delaler.js')} />
          <Route path="dealer" component={require('./routes/Companies/Company.js')} />
          <Route path="pay" component={require('./routes/Pay/Pay.js')} />
          <Route path="bank" component={require('./routes/Pay/Bank.js')} />
          <Route path="bank_edit" component={require('./routes/Pay/BankEdit.js')} />
          <Route path="bank_list" component={require('./routes/Pay/BankList.js')} />

          <Route path="newcus" component={require('./routes/Customer/New.js')} />
          <Route path="editcus" component={require('./routes/Customer/Edit.js')} />
          <Route path="newclue" component={require('./routes/Clue/ClueDetails.js')} />
          <Route path="editclue" component={require('./routes/Clue/Edit.js')} />
          <Route path="newcomdity" component={require('./routes/Commodity/CommodDetails.js')} />

          <Route path="newor" component={require('./routes/Orders/OrdersDetails.js')} />
          <Route path="newstr" component={require('./routes/Strategies/New.js')} />
          <Route path="editstr" component={require('./routes/Strategies/Edit.js')} />
          <Route path="newan" component={require('./routes/Companies/New.js')} />
          <Route path="appan" component={require('./routes/Companies/Apply.js')} />
          <Route path="resetpass" component={require('./routes/Set/ResetPassword.js')} />

          <Route path="deaor" component={require('./routes/Orders/Detail.js')} />
          <Route path="acctor" component={require('./routes/Orders/acct.js')} />
          <Route path="acct_list" component={require('./routes/Orders/acctOrder.js')} />
        </Route>
      </Route>
    </Router>
}
